package DO2;

/**
 * Created by Cai Ye on 2016/4/12.
 */
public class ComplexOf20145208 {
    private double m_dRealPart;
    private double m_dImaginPart;

    public ComplexOf20145208(double m_dRealPart, double m_dImaginPart) {
        this.m_dImaginPart = m_dImaginPart;
        this.m_dRealPart = m_dRealPart;
    }

    public ComplexOf20145208 Add(ComplexOf20145208 c) {
        double realPartSum = m_dRealPart + c.m_dRealPart;
        double imaginPartSum = m_dImaginPart + c.m_dImaginPart;
        return new ComplexOf20145208(realPartSum, imaginPartSum);
    }

    public ComplexOf20145208 Minus(ComplexOf20145208 c) {
        double realPartMin = m_dRealPart - c.m_dRealPart;
        double imaginPartMin = m_dImaginPart - c.m_dImaginPart;
        return new ComplexOf20145208(realPartMin, imaginPartMin);
    }

    public ComplexOf20145208 Multi(ComplexOf20145208 c) {
        double realPartMul = m_dRealPart * c.m_dRealPart;
        double imaginPartMul = m_dImaginPart * c.m_dImaginPart;
        return new ComplexOf20145208(realPartMul, imaginPartMul);
    }

    public String toString() {
        if (m_dImaginPart > 0) {
            if (m_dRealPart == 0)
                return this.m_dImaginPart + "i";
            else
                return this.m_dRealPart + "+" + this.m_dImaginPart + "i";
        } else if (m_dImaginPart < 0) {
            if (m_dRealPart == 0)
                return this.m_dImaginPart + "i";
            else
                return this.m_dRealPart + this.m_dImaginPart + "i";
        } else if (m_dImaginPart == 0) {
            return this.m_dRealPart + "";
        }
        return "Wrong!";
    }
}